package com.lc.hongtai.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.lc.hongtai.MyApplication;
import com.lc.hongtai.R;
import com.lc.hongtai.activity.InvestmentActivity;
import com.lc.hongtai.conn.JsonInvest;
import com.zcx.helper.bound.BoundViewHelper;

import java.text.NumberFormat;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2/22/2016.
 */
public class MyLiNewAdapter_New extends RecyclerView.Adapter<MyLiNewAdapter_New.ViewHolder> {

    private Context context;


    private List<JsonInvest.Info.ListContent> list;


    public MyLiNewAdapter_New(Context context, List<JsonInvest.Info.ListContent> list) {
        this.context = context;
        this.list = list;

    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        // each data item is just a string in this case
        @Bind(R.id.tv_rate)
        TextView tvRate;
        @Bind(R.id.tv_time)
        TextView tvTime;

        @Bind(R.id.tv_name)
        TextView tvName;
        @Bind(R.id.tv_sumMoney)
        TextView tvSumMoney;


        public String str;
        public int a;

        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = BoundViewHelper.boundView(this, MyApplication.scaleScreenHelper.loadView((ViewGroup) LayoutInflater.from(parent.getContext())
                .inflate(R.layout.list_invest_financial, null)));
        //     View view = LayoutInflater.from(context).inflate(R.layout.list_invest_financial, null);
        // set the view's size, margins, paddings and layout parameters
        ViewHolder vh = new ViewHolder(view);
        return vh;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        holder.tvName.setText(list.get(position).borrow_name);
        NumberFormat nfNumber = NumberFormat.getNumberInstance();
        holder.tvRate.setText(list.get(position).borrow_interest_rate);
        holder.tvTime.setText(list.get(position).borrow_duration + list.get(position).borrow_duration_cn);
        holder.tvSumMoney.setText(list.get(position).need);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.putExtra("id", list.get(position).id);
                intent.setClass(context, InvestmentActivity.class);
                context.startActivity(intent);
            }
    /*       @Override
            public void onClick(View v) {

                if (isInvest == INVESTMODE) {
                    Intent intent = new Intent();
                    intent.putExtra("id", list.get(position).id);
                    intent.setClass(context, InvestmentActivity.class);
                    context.startActivity(intent);
                } else if (isInvest == 2) {
                    Intent intent = new Intent();
                    intent.putExtra("id", list.get(position).id);
                    intent.setClass(context, ManageFinancesActivity.class);
                    context.startActivity(intent);
                }
            }*/
        });
    }


    @Override
    public int getItemCount() {
        return list.size();
    }


}
